﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using ERP_RORZE_SYSTEM;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERP_RORZE_DLL.Business
{
    public partial class frm_Check_NegativeIQ : Form
    {
        private INISettings mySetting;
        private SqlConnection myConnection;
        public frm_Check_NegativeIQ()
        {
            InitializeComponent();
            mySetting = new INISettings();
            myConnection = new SqlConnection(mySetting.SQLConnectionString);

            LoadData();        
        }


        ///////////////////////////////////
        /// Load Data From Local Database
        ///////////////////////////////////
        public bool LoadData()
        {
            bool ret = true;

            DataSet sourceDataSet = new DataSet();
            INISettings mySettings = new INISettings();
            SQLManagement mySQLManagement = new SQLManagement();
            mySQLManagement.SQLConnectionString = mySettings.SQLConnectionString;
            string sql = "SELECT [IQID], [CheckMassQuantity], [ImportedQuantity], [LastRemain],"
                + " [ExportedMassQuantity], [Remain], [AdjustedTotal], [AdjustedRemain]"
                + " FROM [VConsumptionAdjustedCheck] ORDER BY AdjustedRemain";
            sourceDataSet = mySQLManagement.SQL_Query(sql);
            if (sourceDataSet != null)
            {
                gridCheckNegativeIQ.DataSource = sourceDataSet.Tables[0];
            }
            else
            {
                MessageBox.Show("There is no data for Check");
                DataTable newTable = new DataTable();
                newTable.Columns.Add("IQID", typeof(string));
                newTable.Columns.Add("CheckMassQuantity", typeof(string));
                newTable.Columns.Add("ImportedQuantity", typeof(float));
                newTable.Columns.Add("LastRemain", typeof(float));
                newTable.Columns.Add("ExportedMassQuantity", typeof(float));
                newTable.Columns.Add("Remain", typeof(float));
                newTable.Columns.Add("AdjustedTotal", typeof(string));
                newTable.Columns.Add("AdjustedRemain", typeof(string));
                gridCheckNegativeIQ.DataSource = newTable;

                ret = false;
            }
            CheckNegativeIQ.Columns[0].Caption = "IQID";
            CheckNegativeIQ.Columns[1].Caption = "Check Mass Quantity";
            CheckNegativeIQ.Columns[2].Caption = "Imported Quantity";
            CheckNegativeIQ.Columns[3].Caption = "Last Remain";
            CheckNegativeIQ.Columns[4].Caption = "Exported Mass Quantity";
            CheckNegativeIQ.Columns[5].Caption = "Remain";
            CheckNegativeIQ.Columns[6].Caption = "Adjusted Total";
            CheckNegativeIQ.Columns[7].Caption = "Adjusted Remain";
            CheckNegativeIQ.BestFitColumns();            
            return ret;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            LoadData();
        }
    }
}
